package top.lixunda.ecommerce.server.good.api.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.GoodGroupDO;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * GoodGroupDO
 *
 * @author Xumda
 * @version time:2020/2/6 22:24
 */
@SuppressWarnings({"WeakerAccess", "unused"})
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class GoodGroupVO {

    /**
     * 分组Id
     */
    private Integer id;

    /**
     * 分组名称
     */
    private String name;

    /**
     * 分组描述
     */
    private String description;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 是否叶节点
     */
    private Integer isLeaf;

    /**
     * 是否根节点
     */
    private Integer isRoot;

    /**
     * 父节点
     */
    private Integer parent;

    /**
     * 备注
     */
    private String remark;

    /**
     * 转换
     *
     * @param goodGroupDO GoodGroupDO
     * @return GoodGroupVO
     */
    public static GoodGroupVO fromGoodGroupDO(GoodGroupDO goodGroupDO) {
        if (ObjectValidators.isEmpty(goodGroupDO)) {
            return null;
        }
        GoodGroupVO vo = new GoodGroupVO();
        BeanUtils.copyProperties(goodGroupDO, vo);
        return vo;
    }

    /**
     * 转换
     *
     * @param list List<GoodGroupDO>
     * @return List GoodGroupVO
     */
    public static List<GoodGroupVO> fromGoodGroupDO(List<GoodGroupDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .filter(Objects::nonNull)
                .map(GoodGroupVO::fromGoodGroupDO)
                .collect(Collectors.toList());
    }

}
